import 'package:distribution_mall_flutter/constant/cf_constant.dart';
import 'package:distribution_mall_flutter/ext/map_ext.dart';
import 'package:distribution_mall_flutter/provider/address/address_query.dart';
import 'package:flutter/material.dart';
import 'package:flutter_animate/flutter_animate.dart';
import 'package:hive/hive.dart';

class AddressHeadLine extends StatelessWidget {
  final List<CityModel> data;
  final int activeIndex;
  final Function(CityModel item, int i) onTap;

  const AddressHeadLine({
    super.key,
    required this.data,
    required this.activeIndex,
    required this.onTap,
  });

  @override
  Widget build(BuildContext context) {
    if (activeIndex == -1) {
      return Container();
    }
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        ...data.mapIndexed((e, i) {
          return Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              GestureDetector(
                onTap: () {
                  onTap(e, i);
                },
                behavior: HitTestBehavior.opaque,
                child: buildItem(true, e.name),
              ),
              if (i != data.length - 1)
                Container(
                    margin: EdgeInsets.only(left: 7),
                    height: 26,
                    child: const VerticalDivider(
                      width: 1,
                      color: Color(0xFF8D8D8D),
                    ))
            ],
          );
        })
      ],
    );
  }

  Widget buildItem(bool isActive, String title) {
    return !isActive
        ? Row(
            children: [
              Container(
                margin: const EdgeInsets.only(right: 12),
                width: 15,
                height: 15,
                decoration: const BoxDecoration(
                    color: Color(0xFFD9D9D9), shape: BoxShape.circle),
              ),
              Expanded(
                child: Text(
                  title,
                  maxLines: 1,
                  style:
                      const TextStyle(color: Color(0xFF777777), fontSize: 16),
                ),
              )
            ],
          )
        : Row(
            children: [
              Container(
                width: 15,
                margin: const EdgeInsets.only(right: 12),
                height: 15,
                decoration: BoxDecoration(
                    color: const Color(0xFF5483BF).withOpacity(0.3),
                    shape: BoxShape.circle),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    Container(
                      padding: const EdgeInsets.all(6),
                      width: 9,
                      height: 9,
                      decoration: const BoxDecoration(
                          color: Color(0xFF5483BF), shape: BoxShape.circle),
                    ),
                  ],
                ),
              ),
              Expanded(
                child: Text(
                  title,
                  maxLines: 1,
                  style:
                      const TextStyle(color: Color(0xFF000000), fontSize: 16),
                ),
              )
            ],
          );
  }
}
